package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.query.RegionQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by 甘静斌 on 2020-08-09 19:37
 */
@Controller
@RequestMapping("region")
public class RegionController {

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IDestinationService destinationService;

    /**
     * 区域管理分页
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") RegionQuery qo){

        Page<Region> page = regionService.query(qo);
        model.addAttribute("page",page );

        return "/region/list";
    }

    /**
     * 模态框下拉框查询目的地
     * @return
     */
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests(){
        List<Destination> list = destinationService.list();
        return list;
    }

    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(long deep){
        List<Destination> list = destinationService.list(deep);
        return list;
    }

    //模态框添加操作
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region){

        regionService.saveOrUpdate(region);
        return JsonResult.success();
    }

    //删除操作
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){

        regionService.delete(id);
        return JsonResult.success();
    }

    /**
     * 区域管理查看功能
     * @param rid
     * @return
     */
    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(String rid){

        List<Destination> list = destinationService.getDestByRegionId(rid);

        return list;

    }

    /**
     * 区域管路设置热门操作
     * @param hot
     * @param id
     * @return
     */
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(int hot,String id){

        regionService.changeHotValue(hot,id);
        return JsonResult.success();
    }
}
